# Copyright (C) 2009  Rob Britton
#
# This file is part of OORegress.
#
# OORegress is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

require 'calc'
require 'stats'

MAX_CMDS = 50
srand Time.now.to_i

filename = ARGV.size > 0 ? ARGV[0] : nil

filename = "file://" + (filename =~ /^\// ? "" : File.dirname(File.expand_path(__FILE__))) + "/" + filename unless filename == nil

calc = OpenOffice::Calc.new(filename)

past_cmds = []
while true
  print ">> "

  cmd, params = $stdin.gets.strip.split(/\s+/, 2).map { |s| s.strip }

  begin
    case cmd
    when "exit", "quit"
      break
    when "regress"
      regress(calc, *parse_params(params))
    when "randoms"
      generate_randoms(calc, *parse_params(params))
    when "help"
    else
    end

=begin
    if cmd != ""
      past_cmds << cmd
      past_cmds.shift if past_cmds > MAX_CMDS
    end
=end
  rescue
    puts $!
    puts $!.backtrace
  end
end

exit
